<template>
  <div class="search">
    <f-form ref="form" :action="api.shopType" :form-key="this.formItem.typeId" :file-ids="fileIds">
      <f-form-item label="分类名称" name="typeName" :required="true" :value="formItem.typeName"/>
      <f-form-item label="费率" type="percentage"  name="typeRate" :required="true" :value="formItem.typeRate"/>
      <f-form-item label="分类logo" type="upload" name="typeLogo" :value="formItem.typeLogo" :file-max="1" @uploadSuccess="uploadSuccess"/>
    </f-form>
  </div>
</template>

<script>
  export default {
    name: 'shopTypeForm',
    props: {},
    data() {
      return {
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载轮播图组件
        fileIds: [],//上传文件ID
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          typeId: '',
          typeCode: 'ProdShop',
          typeName: '',
          typeRate:'0.05',
          typeLogo: '',
          parentId: 0,
          sortOrder: 99,
          groupId:'',
          state:0
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        this.isAdd = true
        if (data && data.typeId) {
          this.$refs.form.getDetails({ typeId: data.typeId }, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //文件上传回调
      uploadSuccess(fileIds, files) {
        this.fileIds = fileIds
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit(this.formItem,callback)
      },
    },
    created() {

    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
